﻿﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <!-- Data Tables -->
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote-bs3.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
@stop
@section('content')
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";font-size:14px;}
        #l-map{height:300px;width:50%;}
        #r-result{width:100%;}
        #l-map,.ibox-content {
            float: none;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=keXdM18CTQm5jrHeydPispemtrz5Y00v"></script>
    <div class="row">
        <div class="col-lg-6">
            <div class="ibox float-e-margins">
                <div class="ibox-content col-sm-8">
                    <form class="form-horizontal m-t" id="commentForm" action="/admin/store/{{ $data->id }}" method="post" enctype='multipart/form-data'>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商家名：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="name" class="form-control" placeholder="请填写商家名" value="{{ $data->name }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">账号：</label>
                            <div class="col-sm-6">
                                <input type="text" name="username" class="form-control" value="{{ $data->username }}" disabled >
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">联系方式：</label>
                            <div class="col-sm-6">
                                <input type="text" name="phone" class="form-control" placeholder="请填写联系方式" value="{{ $data->phone }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">店铺简介：</label>
                            <div class="col-sm-8">
                                <textarea id="ccomment" name="info" class="form-control" required="" aria-required="true">{{ $data->info }}</textarea>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 control-label">具体地址：</label>
                            <div class="col-sm-6">
                                <input type="text"  name="address" id="suggestId"  class="form-control" value="{{ $data->address }}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">经纬度：</label>
                            <div class="col-sm-3">
                                <input type="text" id="lng" name="lng" class="form-control" value="{{ $data->lng }}">
                            </div>
                            <div class="col-sm-3">
                                <input type="text" id="lat" name="lat" class="form-control" value="{{ $data->lat }}">
                            </div>
                        </div>

                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <input type='hidden' name='_method' value="PUT">

                        <div id="l-map"></div>
                        <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                        <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
                        ><strong>修改</strong>
                        </button>
                    </form>
                    <a   class="btn btn-primary" href="/admin/store" >返回</a>
                </div>
            </div>

        </div>
    </div>


@stop
@section('script')
    <!-- SUMMERNOTE -->
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote-zh-CN.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>
    <script src="{{ asset('tools/form-builder/beautifyhtml.js') }}"></script>
    <script>

        $.ajax({
            url:'/admin/store/district',
            async:false,				//是否异步
            type:'post',				//请求方式
            data:{upid:0,_token: "{{ csrf_token() }}"},				//发送的数据
            dataType:'json',			//响应的数据类型
            error:function()			//失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)		//成功时回调函数
            {
                //console.log(data);
                for (var i = 0; i < data.length; i++) {
                    $('#select1').append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                };
            }
        });

        $(document).on("change","select",function(){

            //先清除后面的select，再添加新的select
            $(this).nextAll("select").remove();
            //因为下面需要用到当前对象，但是是另一个函数体内，不能用$(this)
            var ob = $(this);
            var address = '';
            //判断选择的是不是默认的请选择
            if($(this).val() != '--请选择--'){
                var upid = $(this).val();
                //找到每个节点的html值
                for (var y=1;y<=$('select').length;y++){

                    //console.log($('#select'+y).length);
                    if($('#select'+y).length!=0){
                        address += $('#select'+y).find('option:selected').html();
                    }
                }
                 //alert(address);
                $('#suggestId').val(address);
                if($('#select3').length==0){
                    $.ajax({
                        url:'/admin/store/district',
                        async:false,				//是否异步
                        type:'post',				//请求方式
                        data:{upid:upid,_token: "{{ csrf_token() }}"},				//发送的数据
                        dataType:'json',			//响应的数据类型
                        error:function()			//失败时回调函数
                        {
                            alert('ajax请求失败');
                        },
                        success:function(data)		//成功时回调函数
                        {

                            //判断是否还有数据返回
                            if(data.length>0){
                                //新建一个select标签
                                var select = $("<select name="+'select['+data[0].level+"] id="+'select'+data[0].level+"><option>--请选择--</option></select>");
                                //循环给select标签添加上option
                                for (var i = 0; i < data.length; i++) {
                                    $(select).append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                                };
                                console.log($(select));
                                //追加到前一个select后面
                                ob.after(select);
                            }
                        }
                    });
                }
            }

        });
        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
    </script>

    <script>
        $(document).ready(function () {

            $('.summernote').summernote({
                lang: 'zh-CN'
            });

        });
        var edit = function () {
            $("#eg").addClass("no-padding");
            $('.click2edit').summernote({
                lang: 'zh-CN',
                focus: true
            });
        };
        var save = function () {
            $("#eg").removeClass("no-padding");
            var aHTML = $('.click2edit').code(); //save HTML If you need(aHTML: array).
            $('.click2edit').destroy();

        };
        //百度地图接口
        function G(id) {
            return document.getElementById(id);
        }

        var map = new BMap.Map("l-map");
        map.centerAndZoom("北京",12);                   // 初始化地图,设置城市和地图级别。

        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
            {"input" : "suggestId"
                ,"location" : map
            });

        ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if (e.fromitem.index > -1) {
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

            value = "";
            if (e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            G("searchResultPanel").innerHTML = str;
        });

        var myValue;
        ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

            setPlace();
        });

        function setPlace(){
            map.clearOverlays();    //清除地图上所有覆盖物
            function myFun(){
                var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                map.centerAndZoom(pp, 18);
                map.addOverlay(new BMap.Marker(pp));    //添加标注
            }
            var local = new BMap.LocalSearch(map, { //智能搜索
                onSearchComplete: myFun
            });
            local.search(myValue);
        }
        var lng= document.getElementById('lng');
        var lat= document.getElementById('lat');

        map.addEventListener("click",function(e){
            lng.value=e.point.lng;
            lat.value=e.point.lat;
        });
    </script>

@stop
